package org.example.doris.official.mysqljdbc;

import java.sql.*;

public class DorisMySQLDemo {
    public static void main(String[] args) {
        String user = "root";
        String password = "123456";
        String newUrl = "jdbc:mysql://192.168.0.227:9030/testdb?useUnicode=true&characterEncoding=utf8&useTimezone=true&serverTimezone=Asia/Shanghai&useSSL=false&allowPublicKeyRetrieval=true";
        try {
            Connection myCon = DriverManager.getConnection(newUrl, user, password);
            Statement stmt = myCon.createStatement();
            ResultSet result = stmt.executeQuery("show databases");
            ResultSetMetaData metaData = result.getMetaData();
            int columnCount = metaData.getColumnCount();
            while (result.next()) {
                for (int i = 1; i <= columnCount; i++) {
                    System.out.println(result.getObject(i));
                }
            }
        } catch (SQLException e) {
            System.out.println("connect failed:"+e);
        }
    }
}
